| Total Complexity | 2 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { |
||
| 20 | |||
| 21 | @Controller('users') |
||
| 22 | @ApiTags('User') |
||
| 23 | @ApiBearerAuth() |
||
| 24 | @UseGuards(AuthGuard('bearer'), RolesGuard) |
||
| 25 | export class CreateUserAction { |
||
| 26 | constructor( |
||
| 27 | @Inject('ICommandBus') |
||
| 28 | private readonly commandBus: ICommandBus, |
||
| 29 | @Inject('IQueryBus') |
||
| 30 | private readonly queryBus: IQueryBus |
||
| 31 | ) {} |
||
| 32 | |||
| 33 | @Post() |
||
| 34 | @Roles(UserRole.PHOTOGRAPHER) |
||
| 35 | @ApiOperation({summary: 'Create new user'}) |
||
| 36 | public async index(@Body() userDto: UserDTO): Promise<UserView> { |
||
| 37 | try { |
||
| 38 | const { firstName, lastName, email, password, role } = userDto; |
||
| 39 | |||
| 40 | const id = await this.commandBus.execute( |
||
| 41 | new CreateUserCommand( |
||
| 42 | firstName, |
||
| 43 | lastName, |
||
| 44 | email, |
||
| 45 | password, |
||
| 46 | role |
||
| 47 | ) |
||
| 48 | ); |
||
| 49 | |||
| 50 | return await this.queryBus.execute(new GetUserByIdQuery(id)); |
||
| 51 | } catch (e) { |
||
| 52 | throw new BadRequestException(e.message); |
||
| 53 | } |
||
| 56 |